package models;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;

import models.Entities;
import models.Idea;
import models.Topic;
import models.User;

import play.data.validation.Required;
import play.db.jpa.Model;

/**
 * Draft Entity, Create the class draft
 * 
 * @author heba Khattab
 */
@Entity
public class Draft extends Model {
	/**
	 * Title of the draft
	 * 
	 * @author Heba Khattab
	 */
	public String subject;
	/**
	 * Body of the draft
	 * 
	 * @author Heba Khattab
	 */
	@Required
	@Lob
	public String body;
	/**
	 * Time of saving or publishing the draft
	 * 
	 * @author Heba Khattab
	 */
	@Required
	public Date time;
	/**
	 * A user can create many drafts and the draft is created by exactly one
	 * user
	 * 
	 * @author Heba Khattab
	 */
	@ManyToOne
	public User user;

	/**
	 * Constructor
	 * 
	 * @param subject
	 *            title of the draft
	 * @param body
	 *            body of the draft
	 * @param user
	 *            name of the user
	 * 
	 * @author Heba Khattab
	 */
	public Draft(String subject, String body, User user) {
		this.subject = subject;
		this.body = body;
		this.time = new Date();
		this.user = user;
	}

	/**
	 * takes as parameter the draft that will be deleted and deletes it from the
	 * database
	 * 
	 * @param draft
	 *            draft that will be deleted
	 * 
	 * @author Heba Khattab
	 */
	public void deletingDraft(Draft draft) {
		draft.delete();
	}

}
